package Json.test;

import java.util.Iterator;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class JsonSenderActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
    HttpRequest r = new HttpRequest();
    
    JSONObject object=new JSONObject();
    try {
		object.put("name","Amit Kumar");
	    object.put("Max.Marks",new Integer(100));
	    object.put("Min.Marks",new Double(40));
	    object.put("Scored",new Double(66.67));
	    object.put("nickname","Amit");
	    System.out.println(object);
	 
    } catch (JSONException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
    String j;
    
 Log.e("JSON",j = r.sendJSONPost("http://10.0.2.2/header.php", object));
 //Log.e("JSON",r.sendGet(url)Post("10.0.2.2/header.php", object));
 try {
	object = new JSONObject(j);
	JSONArray a = object.names();
	for(int b = 0; b<a.length(); b++ ){
	
	Log.e("JSON",a.getString(b) + " : " + object.get(a.getString(b)));	
		
	}
	
	Log.e("JSON",object.getString("test"));
} catch (JSONException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}  
 
 
	Log.e("JSON","DONE");

    }
}